package com.weipai.springboot.module.controller;

import com.weipai.springboot.model.ProductProperty;
import com.weipai.springboot.model.api.Response;
import com.weipai.springboot.module.service.ProductPropertyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author: 曹朋飞
 * @Date: 2018/08/21 16:49
 * <p>
 * 货品类别属性管理类
 */
@RestController
public class ProductPropertyController {

    @Autowired
    ProductPropertyService productPropertyService;

    /**
     * 分页查询
     *
     * @param page              页码
     * @param size              每页条数
     * @param draw              前台参数，照样返回chang
     * @param productCategoryId 商品的第三级分类的id
     */
    @GetMapping("/productProperty/list/{page}/{size}/{draw}/{productCategoryId}")
    public Response list(@PathVariable("page") Integer page,
                         @PathVariable("size") Integer size,
                         @PathVariable("draw") String draw,
                         @PathVariable("productCategoryId") String productCategoryId) {
        return productPropertyService.selectAllByProductCategoryId(page, size, draw, productCategoryId);
    }
    
    /**
     * 保存货品类别属性
     *
     * @param productProperty
     * @return
     */
    @PostMapping("/productProperty/save")
    public Response save(ProductProperty productProperty, String propertyOptionValue) {
        return productPropertyService.save(productProperty, propertyOptionValue);
    }

    /**
     * 修改
     * @return
     */
    @PostMapping("/productProperty/update")
    public Response update(String id, String propertyName, String[] propertyOptionValue) {
        return productPropertyService.update(id, propertyName, propertyOptionValue);
    }

    /**
     * 查询详情
     *
     * @param id：主键
     * @return
     */
    @GetMapping("/productProperty/getProductPropertyById")
    public Response getProductPropertyById(String id) {
        return productPropertyService.getProductPropertyById(id);
    }

    /**
     * 删除
     * @param id：主键              --------------------如果有 子属性 , 前端必须提示 "有关联数据,不能删除"
     * @return
     */
    @DeleteMapping("/productProperty/deleteById/{id}")
    public Response deleteById(@PathVariable("id") String id) {
        return productPropertyService.deleteById(id);
    }

    /**
     * 批量删除
     *
     * @param id:主键的id集合
     * @return
     */
    @DeleteMapping("/productProperty/batchDeleteById/{id}")
    public Response batchDeleteById(@PathVariable("id") String[] id) {
        return productPropertyService.batchDeleteById(id);
    }

    /**
     * 更改状态
     *
     * @param id
     * @param status
     * @return
     */
    @GetMapping("/productProperty/changeStatus/{id}/{status}")
    public Response changeStatus(@PathVariable("id") String id,
                                 @PathVariable("status") Integer status) {
        return productPropertyService.changeStatus(id, status);
    }

    /**
     * 通过第三级的商品分类获取到属性与属性选项
     * @param id：第三级分类的id
     * @return
     */
    @GetMapping("/productProperty/getOptionByProductCategoryId/{productCategoryId}/{spuNumber}/{type}")
    public Response getOptionByProductCategoryId(@PathVariable("productCategoryId")String id,
                                                 @PathVariable("spuNumber") String spuNumber,
                                                 @PathVariable("type") String type){
        return productPropertyService.getOptionByProductCategoryId(id, spuNumber, type);
    }

    /**
     * 通过产品的id来查询出此商品下面的所有属性和属性选项
     * @return
     */
    @GetMapping("/productProperty/getOptionByProductId/{productId}/{spuNumber}")
    public Response getOptionBypProductId(@PathVariable("productId") String productId, 
                                          @PathVariable("spuNumber") String spuNumber){
        return productPropertyService.getOptionByProductId(productId, spuNumber,"true");
    }
    
    
    
    
    

}
